/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package load.math;

import core.DispatcherPort;
import core.InPort;
import core.OutPort;
import core.StdNode;
import core.TriggerPort;

/**
 *
 * @author Jelle
 */
public class SmartAddition extends StdNode {

    private DispatcherPort resChanged = new DispatcherPort();
    private TriggerPort argChanged = new TriggerPort() {


        @Override
        protected void callInternal() {
            resChanged.callTargets();
        }
    };
    private InPort arg1 = new InPort(java.lang.Object.class, argChanged);
    private InPort arg2 = new InPort(java.lang.Object.class, argChanged);
    private OutPort res = new OutPort(java.lang.Object.class, resChanged) {


        @Override
        protected Object getValueInternal() {
            Object result = null;
            try {
                result =  (Integer) arg1.getValue() + (Integer) arg2.getValue();
            } catch (Exception ex) {
                try {
                    result =  (Double) arg1.getValue() + (Double) arg2.getValue();
                } catch (Exception ex2) {
                    try {
                        String res = "";
                        res += (String) arg1.getValue();
                        res += (String) arg2.getValue();
                        result =  res;
                    } catch (Exception ex3) {
                        result =  null;
                    }
                }
            }
            return result;
        }
    };

    public SmartAddition() {
        autoPutPorts();
    }
}
